package com.cf.limit;


import com.cf.limit.core.LimitStore;
import com.cf.limit.core.ZLimitAspect;
import com.cf.limit.core.frequency.IpLimitChecker;
import com.cf.limit.core.frequency.IpLimitProperty;
import com.cf.limit.core.frequency.JedisLimitStore;
import com.cf.limit.core.service.BlackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * game-server-RequestLimitConfig
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/5/16 下午 12:26
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(IpLimitProperty.class)
public class RequestLimitConfig {


    @Bean
    @ConditionalOnMissingBean(BlackService.class)
    public BlackService blackService() {
        log.info("缺失BlackService，实例化BlackService");
        return new BlackService();
    }

    @Bean
    public LimitStore jedisLimitStore() {
        log.info("当前环境中存在JedisCluster，创建JedisLimitStore");
        return new JedisLimitStore();
    }

    @Bean
    public ZLimitAspect limitAspect() {
        return new ZLimitAspect();
    }

    @Bean
    public IpLimitChecker defaultIpLimitChecker() {
        log.info("缺失IpLimitChecker，实例化IpLimitChecker");
        return new IpLimitChecker();
    }

}
